package org.mparts.client.place;

import org.mparts.client.activity.CatalogActivity;
import org.mparts.client.mvp.ActivityPlace;

import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class CatalogPlace extends ActivityPlace<CatalogActivity> {

	public static final String VIEW_HISTORY_TOKEN = "!catalog";

	@Inject
	public CatalogPlace(CatalogActivity activity) {
		super(activity);
	}
	
	

	@Override
	public CatalogActivity getActivity() {
		activity.init(this);
		return super.getActivity();
	}



	@Prefix(value = VIEW_HISTORY_TOKEN)
	public static class Tokenizer implements PlaceTokenizer<CatalogPlace> {

		private final Provider<CatalogPlace> placeProvider;

		@Inject
		public Tokenizer(Provider<CatalogPlace> placeProvider) {
			this.placeProvider = placeProvider;
		}

		@Override
		public CatalogPlace getPlace(String token) {
			CatalogPlace place = placeProvider.get();
			place.setPlaceName(token);
			return place;
		}

		@Override
		public String getToken(CatalogPlace place) {
			return place.getPlaceName();
		}
	}



	@Override
	public String getHistoryToken() {
		return VIEW_HISTORY_TOKEN;
	}
}
